/*
 * ClasspathClassLoader.java
 */

package xq.util;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ThorntonRP
 */
public class ClasspathClassLoader extends URLClassLoader {

	public ClasspathClassLoader(String classpath) {
		super(toURLs(classpath));
	}
	
	private static List<URL> toURLs(String classpath) {
		String[] fileNames = classpath.split(File.pathSeparator);
		List<URL> urls = new ArrayList<URL>(fileNames.length);
		for (String fileName : fileNames) {
			File f = new File(fileName);
			try {
				urls.add(f.toURI().toURL());
			} catch (MalformedURLException ex) {
				ex.printStackTrace();
			}
		}
		return urls;
	}
}
